feat: enhance dashboard with student progress tracking and session attendance#21
feat: enhance dashboard with student progress tracking and session attendance#21ayesha1145 wants to merge 1 commit intoalphaonelabs:mainfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds POST /api/attendance to record per-session attendance; extends GET /api/dashboard to include per-activity Changes
Sequence DiagramsequenceDiagram
participant User as User (Client)
participant UI as Dashboard UI
participant API as Worker (Server)
participant DB as Database
User->>UI: mark attendance (session_id, status)
UI->>API: POST /api/attendance {session_id, status}
API->>API: validate auth & inputs
API->>DB: SELECT session, activity, enrollment
DB-->>API: session + enrollment result
API->>DB: INSERT INTO session_attendance ON CONFLICT UPDATE
DB-->>API: upsert confirmation
API-->>UI: {session_id, status}
UI->>API: GET /api/dashboard
API->>DB: query joined activities, counts (total_sessions, attended_sessions), hosted activities, batched tags
DB-->>API: activities + stats + tags
API-->>UI: {stats, joined_activities[], hosted_activities[]}
UI->>User: render stat cards and per-activity progress
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@public/dashboard.html`:
- Around line 154-158: The progress bar string assigned to progressBar lacks
ARIA attributes; update the generated element for the progress bar (the div
containing class "bg-indigo-500 ...") to include role="progressbar",
aria-valuemin="0", aria-valuemax equal to a.total_sessions or 100 depending on
your model, aria-valuenow set to the numeric value (use a.attended_sessions or
pct), and an aria-label or aria-valuetext that describes the progress (e.g.,
“Progress: X of Y sessions (Z%)”) so screen readers can perceive the same info
as the visual meter; locate the variables pct, a.progress_pct,
a.attended_sessions and a.total_sessions and inject these attributes into the
progress bar div generation.
In `@src/worker.py`:
- Around line 13-14: Replace the EN DASH characters in the route documentation
string with normal hyphen-minus characters so the paths are copy-paste safe;
locate the module-level docstring or the string containing "GET /api/dashboard
– personal dashboard with progress stats" and "POST /api/attendance –
mark session attendance [auth]" and swap each "–" to "-"
(hyphen-minus) in that string.
- Around line 914-925: The loop builds hosted entries using dict-style row
access (r["id"], r["title"], etc.) which is inconsistent with the rest of the
file (use attribute access like row.id). Update the loop that iterates over
res.results to use attribute access (e.g., r.id, r.title, r.type, r.format,
r.schedule_type, r.participant_count, r.session_count, r.created_at) and also
map tag rows from t_res to t.name instead of t["name"]; keep the same
prepare/bind logic and the hosted append shape unchanged.
- Around line 1244-1255: The current check-then-insert/update using
env.DB.prepare with a SELECT then conditional UPDATE/INSERT on
session_attendance (session_id,user_id) is racy and lacks error handling;
replace it with an atomic upsert using SQLite's INSERT ... ON CONFLICT
(session_id, user_id) DO UPDATE to set status (or use a single SQL statement
executed via env.DB.prepare) and remove the separate SELECT branch, and if you
keep the two-step flow then wrap the INSERT in a try/except similar to api_join
to catch UNIQUE constraint errors, log the failure, and return a controlled
response via ok/error; target the block around the functions/variables
env.DB.prepare, session_attendance, new_id(), status, and ok().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 33b20b7d-3bcb-4ca3-8300-f7884bfbd7b3
📒 Files selected for processing (2)
public/dashboard.htmlsrc/worker.py
02be33c to
85d9421
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/worker.py`:
- Around line 915-917: The per-activity tag SELECT (using env.DB.prepare(...)
and binding r["id"] into t_res) must be replaced with a single batched query:
collect all activity IDs returned earlier, run one SELECT joining tags and
activity_tags with WHERE activity_id IN (...), then group results into a mapping
of activity_id -> list of tags in Python and use that map when building the
hosted and joined lists (the current per-row logic that reads t_res should be
switched to lookup in this map); also apply the same batching change for the
similar lookup around the code referenced at lines 943-945.
- Around line 1224-1228: The code currently defaults status = body.get("status",
"attended") which can silently mark missing statuses as attended; change this to
require an explicit status by using status = body.get("status") (no default) and
add a check if not status: return err("status is required"), then keep the
existing validation if status not in ("registered","attended","missed") to
return err("status must be registered, attended, or missed"); reference the
variables/status check and err(...) in the same block (status, session_id,
body.get, err) when making the change.
- Around line 1238-1242: The current gate uses is_host to allow hosts to bypass
enrollment (is_host from env.DB.prepare(...).bind(...).first()) so hosts can
write attendance without an enrollment row; change the logic to require an
enrollment row (enr) regardless of is_host by removing is_host from the
allowlist and returning err("You must be enrolled in this activity", 403) when
enr is falsy; keep the activity existence check if needed but do not let is_host
bypass the enrollment requirement in this handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 170949b9-900e-4003-b44f-c6467b6a1a0b
📒 Files selected for processing (2)
public/dashboard.htmlsrc/worker.py
85d9421 to
117be7c
Compare
|
Addressed latest CodeRabbit feedback:
|
|
@A1L13N This PR is ready for review — all feedback has been addressed ✅ |
|
@copilot fix the conflicts |
117be7c to
93e65df
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
src/worker.py (2)
13-14:⚠️ Potential issue | 🟡 MinorMinor: Replace EN DASH with HYPHEN-MINUS in route documentation.
The docstring uses EN DASH (
–) instead of the standard HYPHEN-MINUS (-). While this doesn't affect runtime behavior, it can cause copy-paste issues if someone tries to use these paths directly.📝 Suggested fix
- GET /api/dashboard – personal dashboard with progress stats - POST /api/attendance – mark session attendance [auth] + GET /api/dashboard - personal dashboard with progress stats + POST /api/attendance - mark session attendance [auth]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/worker.py` around lines 13 - 14, The route documentation in the docstring uses EN DASH characters (–) after the paths (e.g. the lines with "GET /api/dashboard – personal dashboard with progress stats" and "POST /api/attendance – mark session attendance [auth]"); update those separators to the standard ASCII hyphen-minus (-) so the lines become "GET /api/dashboard - personal dashboard..." and "POST /api/attendance - mark session attendance..." to avoid copy-paste issues.
1063-1063:⚠️ Potential issue | 🔴 CriticalCritical: Using deprecated
decrypt()instead ofawait decrypt_aes().This line calls the synchronous
decrypt()function, which has been deprecated and will raise aRuntimeErrorat runtime (see lines 203-205). This will cause the entire dashboard endpoint to fail for any user with joined activities.🐛 Proposed fix
- "host_name": decrypt(r["host_name_enc"] or "", enc), + "host_name": await decrypt_aes(r["host_name_enc"] or "", enc),As per coding guidelines: "Ensure proper error handling and logging."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/worker.py` at line 1063, Replace the deprecated synchronous decrypt() call with the async decrypt_aes() and await it where the host_name is built (replace "host_name": decrypt(r["host_name_enc"] or "", enc) with an awaited call to decrypt_aes); ensure the enclosing function is async or that you use await within an async map/gather, and wrap the await in try/except to catch RuntimeError (or any decryption error) and log the error via the existing logger before falling back to a safe value (e.g., empty string) so runtime failures for joined activities don’t crash the endpoint.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/worker.py`:
- Around line 1351-1358: The capture_exception call inside the exception handler
for the upsert in api_mark_attendance is missing request and environment
context; update the exception handling around
env.DB.prepare(...).bind(...).run() so that capture_exception(exc, req=req,
env=env, where="api_mark_attendance") (or the project's canonical param names)
is invoked before returning the error, ensuring req and env are passed alongside
exc and where to capture full context for debugging.
---
Duplicate comments:
In `@src/worker.py`:
- Around line 13-14: The route documentation in the docstring uses EN DASH
characters (–) after the paths (e.g. the lines with "GET /api/dashboard
– personal dashboard with progress stats" and "POST /api/attendance –
mark session attendance [auth]"); update those separators to the
standard ASCII hyphen-minus (-) so the lines become "GET /api/dashboard
- personal dashboard..." and "POST /api/attendance - mark session
attendance..." to avoid copy-paste issues.
- Line 1063: Replace the deprecated synchronous decrypt() call with the async
decrypt_aes() and await it where the host_name is built (replace "host_name":
decrypt(r["host_name_enc"] or "", enc) with an awaited call to decrypt_aes);
ensure the enclosing function is async or that you use await within an async
map/gather, and wrap the await in try/except to catch RuntimeError (or any
decryption error) and log the error via the existing logger before falling back
to a safe value (e.g., empty string) so runtime failures for joined activities
don’t crash the endpoint.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0eaf437a-cc34-4c85-9dfb-efed9fa8ebfb
📒 Files selected for processing (2)
public/dashboard.htmlsrc/worker.py
93e65df to
c0fb4a9
Compare
|
Fixed nitpick: added req and env parameters to capture_exception() in api_mark_attendance for richer error logging context in production. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/worker.py`:
- Around line 999-1078: Add tests that cover the new /api/dashboard aggregation
and the enrollment-gated attendance upsert flows: create fixtures for activities
with zero sessions and with >0 sessions, users who are enrolled (enr_status
values including default "registered" and "active") and non-enrolled users, and
exercise re-marking the same session twice. For the dashboard endpoint assert
hosted and joined payload shapes (hosted, joined lists), joined[*].progress_pct,
joined[*].attended_sessions, stats keys (total_joined, completed, in_progress,
total_sessions_attended, hosted_count) and that zero-session activities yield
progress_pct 0 and don’t inflate in_progress; for attendance upserts simulate
attendance calls for an enrolled vs non-enrolled user and re-marking the same
session to ensure attendance increments only when allowed and idempotency holds.
Locate tests to cover the code paths populating joined, hosted, stats and the
enrollment-gated attendance upsert logic referenced in the PR.
- Around line 1059-1068: The code is calling the deprecated sync shim
decrypt(...) which raises RuntimeError; replace that call with the async decrypt
helper (e.g., await decrypt_async(...) or await decrypt(... ) if the async
function is named decrypt) when building the "host_name" field so the operation
is awaited and non-blocking; update the surrounding function (the
generator/handler that builds joined) to be async or perform an asyncio.gather
over multiple decrypt calls so the list comprehension/loop that produces joined
can await the async helper for r["host_name_enc"] and pass the enc parameter
correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: a07fd1f8-62ea-499b-a9a2-c38912630c98
📒 Files selected for processing (2)
public/dashboard.htmlsrc/worker.py
c0fb4a9 to
679d03b
Compare
|
Fixed critical: removed duplicate old code block left by rebase — eliminated the stale hosted/joined loops that used attribute-style row access (r.id) and the deprecated sync decrypt() call on host_name. The dashboard now correctly uses dict-style access and await decrypt_aes() throughout. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@public/dashboard.html`:
- Around line 100-106: The variable totalParts (computed as hosted.reduce((s,a)
=> s + (a.participant_count||0), 0)) is dead code after switching to data.stats;
remove the totalParts declaration to clean up unused code (leave hosted,
participant_count, and statCard usage intact) so the dashboard.html no longer
computes an unused sum.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 14c73050-7ed8-47bd-9598-94cc3c40e663
📒 Files selected for processing (2)
public/dashboard.htmlsrc/worker.py
679d03b to
f42d877
Compare
|
Fixed nitpick: removed unused totalParts variable — leftover from before stats object was introduced, no longer referenced anywhere in the updated dashboard. |
Adds student progress tracking to the dashboard and a new attendance API endpoint.
Changes:
Features:
Purpose
Enhance the dashboard with per-activity student progress tracking and add session attendance management so enrolled users can mark and update attendance. Provide server-driven aggregate stats to simplify client logic and improve consistency.
Key Modifications
Backend (src/worker.py)
Frontend (public/dashboard.html)
Impact on Functionality & UX
Notes for Review